<?php
require_once("../../resources/commons.php");
require_once("../../data/Item.php");
require_once("dashboard_commons.php");

SessionManager::getInstance()->checkSession();

//A simple script which displays the action associated with the specified Id
if(isset($_REQUEST["id"])){
	$l_action=Item::getFromPrimaryKey(base64_decode($_REQUEST["id"]));

	if(isset($l_action)){
		//Display action only if the user has created the action or has been allocated it.
		$l_me=SessionManager::getCurrentLoggedUserId();
		if($l_action->isAccessAllowed($l_me)){
			displayTop("Action: " . $_REQUEST["id"],null,null);
			displayAction($l_action);
		}else{
			displayError("Forbidden, not sufficient rights");
		}
	}else{
		echo "<b>Unknown action</b>";
	}
?>
<script type="text/javascript">
<!--
/**
 * This JavaScript function manage the close button.
 * If the last page was the RSS feed or any page outside the ROOT_PATH, the button will link to the home page of ITAB.
 * If the last page was within the ROOT_PATH, just do a history.back()
 */
function closeDisplayAction(){
	var previousUrl="<?=$_SERVER["HTTP_REFERER"] ?>";
	var reIatbRoot=new RegExp("^<?=getServerURL(ROOT_PATH); ?>","i");
	var reRssPath=new RegExp("^<?=getServerURL(ROOT_PATH); ?>/rss/","i");
	if(!reIatbRoot.test(previousUrl) || reRssPath.test(previousUrl)){
		window.location="<?=getServerURL(ROOT_PATH); ?>/apps/";
	}else{
		history.back();
	}
}
//-->
</script>
<center><br/><a href="#" onClick="{closeDisplayAction();return false;}"><img border="0" src="<?=ROOT_PATH ?>/apps/resources/images/close.png"/></a></center>
<?php	
	displayBottom();
}else{
	//Redirect to home if invalid parameter is provided
	HTTP::redirect(ROOT_PATH . "/apps/");
}
?>